#ifndef _lib_fs_block_l0_
#define _lib_fs_block_l0_

#include "types.h"
#include "lib_host.h"
#include "lib_fs_disk_io.h"
#include "unix.h"


#define BLOCK_SIZE        512
//#define FILE_NAME_SIZE    40
//#define FILE_NAME_SIZE    19
#define FILE_NAME_SIZE    10
#define FULL_NAME_SIZE    128
#define BLOCK_ALLOC       0x00000000 /* special iblock value that cause block alloc */
#define BLOCK_EOF         0xffffffff /* special iblock value that means end of file */
#define BLOCK_EMPTY       0xff /* it defines if block_erase has to put bits to 1 instead of to 0 */

typedef enum
{
    FILE_MEDIA_UNKNOWN,
    FILE_MEDIA_RAM,      /* not implemented */
    FILE_MEDIA_FLASH,    /* not implemented */
    FILE_MEDIA_DISK
} OS_MediaType_e;

typedef struct
{
    char_t   name[FILE_NAME_SIZE];
    uint32_t iblock;      /* first block of file */
    uint32_t modifiedTime;
    uint32_t length;
    uint8_t  isDirectory;
    uint8_t  attributes;
    uint8_t  valid;
    uint8_t  mediaType;
    uint16_t blockSize;
    uint8_t  pad[2];
} old___OS_FileEntry_t;

typedef struct
{
    char_t   name[FILE_NAME_SIZE];
    uint32_t iblock;
    uint32_t modifiedTime;
    uint32_t length;
    uint8_t  mediaType;
    uint16_t blockSize;
    uint8_t  isDirectory;
    uint8_t  valid;
    uint8_t  attributes;
} OS_FileEntry_t;

typedef struct
{
    uint32_t next;
    uint8_t  data[BLOCK_SIZE - sizeof(uint32_t)];
} OS_Block_t;

typedef struct
{
    OS_FileEntry_t fileEntry;               /* written to directory upon OS_fclose() */
    uint8_t        fileModified;
    uint8_t        blockModified;
    uint8_t        pad1, pad2;
    uint32_t       iblock;                   /* index of block */
    uint32_t       blockOffset;              /* byte offset into block */
    uint32_t       fileOffset;               /* byte offset into file */
    char_t         fullname[FULL_NAME_SIZE]; /* includes full path */
    OS_Block_t     *block;
    OS_Block_t     blockLocal;               /* used by media_disk */
}OS_FILE_t;

#include "lib_fs_block_l0.interface"

#endif

